<?php

class Pre_li {
	var $flag = 'right';
	var $data_list = array();
	var $open = false;
	/*构造函数,类初始化时，被调用*/
	function __construct($config = '')
	{
		$this->flag = $config['flag']?$config['flag']:'right';
		$this->data_list = $config['list']?$config['list']:array();
	}
	/*
		<li>
		<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>武侯区武阳大道二段</span><p>&yen;16-40</p></a>
		<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>武侯区武阳大道二段</span><p>&yen;16-40</p></a>
		<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>武侯区武阳大道二段哈哈哈哈啊</span><p>&yen;16-40哈哈哈哈啊</p></a>
		</li>
		<li class="leftli">
		<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>武侯区武阳大道二段</span><p>&yen;16-40</p></a>
		<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>武侯区武阳大道二段</span><p>&yen;16-40</p></a>
		<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>武侯区武阳大道二段哈哈哈哈啊</span><p>&yen;16-40哈哈哈哈啊</p></a>
		</li>
	*/
	
	function predata()
	{
		$i = 0;
		$str = '';
		foreach($this->data_list as $k => $v)
		{
			$str .= $this->_arr_pre($i,$v);
			$i++;
		}
		if($this->open == true)
		{
			$str .= '</li>';
		}
		return $str;
	}
	
	private function _li()
	{
		$str = '';
		switch($this->flag)
		{
			case 'right':
				$str .= '<li>';
				$this->flag = 'left';
				break;
			default :
				$str .= '<li class="leftli">';
				$this->flag = 'right';
				break;
		}
		$this->open = true;
		return $str;
	}
	
	private function _arr_pre($i,$v)
	{
		$str = '';
		if($this->open==false){
			switch($i)
			{
				case 0:
				case 3:
					$str .= $this->_li();
					break;
				default:break;
			}
		}
		$str .= '<a class="roomitem" href="javascript:void(0)"><b></b><img src="/img/cangdi3.png" /><span>'.$v['address'].'</span><p>&yen;16-40</p></a>';
		if($this->open==true){
			switch($i)
			{
				case 2:
				case 5:
					$str .= '</li>';
					break;
				default:break;
			}
		}
		
		return $str;
	}
}
?>